package android.meetingatsb.common

import android.content.Context
import android.graphics.Bitmap
import android.os.Parcel
import android.os.Parcelable

class User(var name: String, var group: String, var university: String, var age: Int, var gender: String, var rating: Float) : Parcelable {
    var icon: Bitmap? = null

    override fun describeContents(): Int {
        return 0
    }

    override fun writeToParcel(dest: Parcel?, flags: Int) {
        dest?.writeString(name)
        dest?.writeString(group)
        dest?.writeString(university)
        dest?.writeInt(age)
        dest?.writeString(gender)
        dest?.writeFloat(rating)
    }


    constructor(parcel: Parcel) : this(
            parcel.readString(),
            parcel.readString(),
            parcel.readString(),
            parcel.readInt(),
            parcel.readString(),
            parcel.readFloat()) {
    }

    companion object CREATOR : Parcelable.Creator<User> {
        override fun createFromParcel(parcel: Parcel): User {
            return User(parcel)
        }

        override fun newArray(size: Int): Array<User?> {
            return arrayOfNulls(size)
        }

        fun getCurrUser(context: Context): User? = Loader.getUser(context)

        fun setCurrUser(context: Context, user: User) {
            Loader.saveUser(context, user)
        }
    }
}